using System;
using System.Configuration;
using System.Collections.Generic;
using System.Collections.Specialized;

namespace GameTools
{
	public class ConfigMgr 
	{  
		/// <summary>  
		/// 写入值  
		/// </summary>  
		/// <param name="key"></param>  
		/// <param name="value"></param>  
		public static void SetValue(string key, string value)  
		{  
			System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);  
			if (config.AppSettings.Settings[key] == null)  
			{  
				config.AppSettings.Settings.Add(key, value);  
			}  
			else  
			{  
				config.AppSettings.Settings[key].Value = value;  
			}  
			config.Save(ConfigurationSaveMode.Modified);  
			ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件  
		}  

		/// <summary>  
		/// 读取指定key的值  
		/// </summary>  
		/// <param name="key"></param>  
		/// <returns></returns>  
		public static string GetValue(string key)  
		{   

			System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);  
			if (config.AppSettings.Settings[key] == null)  
				return "";  
			else  
				return config.AppSettings.Settings[key].Value;
		}  

        public static string GetSdkPluginValue(string name, string key)  
        {   
            var cfgSection = ConfigurationManager.GetSection(name) as NameValueCollection;
            if (cfgSection == null)
                return "";

            return cfgSection[key];
        }
	}
}

